Skip to content

[MSSQL] Ensure consistent ordering of CDC operations - #742

Merged
Rentacookie merged 15 commits into
mainfrom
fix/mssql-operation-sequence-order
Aug 12, 2026
Merged

[MSSQL] Ensure consistent ordering of CDC operations#742
Rentacookie merged 15 commits into
mainfrom
fix/mssql-operation-sequence-order

Conversation

@Rentacookie

@Rentacookie Rentacookie commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

Summary

This fixes an issue that was discovered where deferred updates could result in missing row updates.
Deferred updates are recorded in the CDC tables as a paired DELETE and INSERT operation, with the 2 operations having the same sequence number in the same transaction. This caused problems with the ordering of operations in the same transaction and the INSERT could be processed before the DELETE causing the replicated row to disappear.

Changes

  • Use operation as a tie breaker when ordering CDC results within a transaction.
  • Identify deferred updates and process them as normal updates, which reduces bucket operation.
  • Replaced previous optimistic transaction count estimate with an accurate count. The transactions replicated metric should now be more accurate.
  • Switched to streaming for the CDC Polling query

Testing

Added new CDCPoller.test.ts unit tests which helped diagnose the main issue and confirms the fixes.
Moved MSSQLSourceTable test cases to own test file.

AI Disclosure

Used Clause Opus 5 to replicate the issue with tests and implement then implement the fix. Also reviewed and verified changeds with GPT 5.6.

- Ensure correct ordering of CDC results
- Handle deferred updates
- Correctly count processed transactions in each polling cycle
- Improved logging
- Added tests
@changeset-bot

changeset-bot Bot commented Jul 31, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: faa492f

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 12 packages
Name Type
@powersync/service-module-mssql Minor
@powersync/service-schema Patch
@powersync/service-image Patch
@powersync/service-core Patch
@powersync/service-module-convex Patch
@powersync/service-module-core Patch
@powersync/service-module-mongodb-storage Patch
@powersync/service-module-mongodb Patch
@powersync/service-module-mysql Patch
@powersync/service-module-postgres-storage Patch
@powersync/service-module-postgres Patch
test-client Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Comment thread modules/module-mssql/src/replication/CDCPoller.ts
Comment thread modules/module-mssql/src/replication/CDCPoller.ts Outdated
Comment thread modules/module-mssql/src/replication/CDCPoller.ts Outdated
Comment thread modules/module-mssql/src/replication/CDCPoller.ts Outdated
stevensJourney
stevensJourney previously approved these changes Aug 11, 2026
Comment thread packages/service-core/src/storage/SourceEntity.ts
Comment thread modules/module-mssql/test/src/CaptureReconciler.test.ts

@stevensJourney stevensJourney left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@Rentacookie
Rentacookie merged commit 9d0b129 into main Aug 12, 2026
46 checks passed
@Rentacookie
Rentacookie deleted the fix/mssql-operation-sequence-order branch August 12, 2026 09:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants